package com.ttbj.product.moveRule.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ttbj.api.dto.moveRule.MoveRuleDto;
import com.ttbj.api.exception.BusinessException;
import com.ttbj.api.moveRule.MoveRuleService;
import com.ttbj.constant.PlatFormErrorCode;
import com.ttbj.constant.annotation.SystemServiceLog;
import com.ttbj.core.util.DtoTransitionUtils;
import com.ttbj.moveRule.bean.po.MoveRule;
import com.ttbj.moveRule.dao.MoveRuleMapper;

@Service("moveRuleService")
public class MoveRuleServiceImpl implements MoveRuleService{
	
	@Autowired
	private MoveRuleMapper moveRuleMapper;

	@Override
	public MoveRuleDto findMoveRuleInfo() throws BusinessException {
		MoveRule moveRule = this.moveRuleMapper.queryMoveRuleInfo();
		MoveRuleDto moveRuleDto = (MoveRuleDto) DtoTransitionUtils.trans(MoveRuleDto.class, moveRule);
		return moveRuleDto;
	}

	@Override
	@Transactional
	@SystemServiceLog(description="修改搬家计费配置")
	public void editMoveRuleInfo(MoveRuleDto moveRuleDto) throws BusinessException {
		if (null == moveRuleDto) {
			throw new BusinessException("参数有误", PlatFormErrorCode.PARAM_IS_NULL.code());
		}
		MoveRule moveRule = (MoveRule) DtoTransitionUtils.trans(MoveRule.class, moveRuleDto);
		int result = this.moveRuleMapper.updateMoveRuleInfo(moveRule);
		if (result == 0) {
			throw new BusinessException("更改失败，重新更改", PlatFormErrorCode.PARAM_IS_NULL.code());
		}
	}

}
